package com.bfb.helpers;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Helper class for some server related functions.
 * 
 */
public class ServerUtilities {

	/**
	 * Starts a new thread in the background with the {@link Runnable} r.
	 * 
	 * @param r
	 * 
	 */
	public static void background(final Runnable r) {
		new Thread() {
			@Override
			public void run() {
				r.run();
			}
		}.start();
	}

	/**
	 * Takes the input stream and converts it into a string for easier
	 * manipulation.
	 * 
	 * @param is
	 *            The input stream
	 * 
	 * @return String
	 * 
	 * @throws IOException
	 */
	public static String getContentFromStream(InputStream is)
			throws IOException {
		BufferedReader r = new BufferedReader(new InputStreamReader(is));
		StringBuilder total = new StringBuilder();
		String line;
		while ((line = r.readLine()) != null) {
			total.append(line);
		}
		return total.toString();
	}
}
